<template>
	<view class="page-fade-in" :style="{opacity: pageOpc}">
		<template v-if="pageOpc">
			<view class="content">
				<view class="top-box flexWrap">
					<view class="screen-box">
						<view class="date-box flexWrapNo" @tap="showDate()">
							<image src="/static/index/calendar.png" class="calendar-icon"></image>
							{{starTime}}
							<text class="triangle"></text>
						</view>
						<view class="date-boxs" v-if="dateFlag">
							<view class="date-title">时间筛选</view>
							<view class="date-cont flexWrap">
								<view class="screen-item flexWrap">
									<picker mode="date" :data-index='0' :value="starTime" @change="bindDateChange" :end="date" fields="month">
										<view class="select-input" v-if="starTime">{{starTime}}</view>
										<view class="select-input" v-else>请选择时间</view>
									</picker>
									<text class="triangle"></text>
								</view>
							</view>
							<view class="determine-btn flexWrapNo">
								<!-- <view @tap="reSet()">重置</view> -->
								<view class="determine" @tap="submit()">确认</view>
							</view>
						</view>
						<view class="mask-wrap" v-if="dateFlag" @tap="closeDate()"></view>
					</view>
				</view>
				<view class="total-box flexWrap">
					<view>合计：</view>
					<view class="total-num">{{totalMoney||'0.00'}}</view>
					<view></view>
				</view>
				<scroll-view class="VerticalMain" lower-threshold="50rpx" scroll-y
					scroll-with-animation style="height: calc(69vh);" >
					<view class="data-box">
						<!-- dataList -->
						<view class="data-item flexWrap" v-for="(item,index) in dataList" :key="index">
							<view class="left">
								<view>结算日期：{{item.settlement_date}}</view>
								<view class="jz">账单日期：{{item.cashout_date}}</view>
							</view>
							<view>¥{{item.cashout_amount}}</view>
						</view>
					</view>
				</scroll-view>
				<view class="tips-box">
					<view class="tips-item">说明：</view>
					<view class="tips-item">1、此金额为每日可提现金额；</view>
					<view class="tips-item">2、仅结算小程序收入，团购收入由第三方平台（美团/抖音/高德等）结算;</view>
					<view class="tips-item">3、D+2到账，当天收入将在2天以后自动结算到账。</view>
				</view>
				
				<!--操作指引悬浮按钮 -->
				<guideline :path="'pages/manage/calculationRecords'"></guideline>
			</view>
		</template>
	</view>
</template>

<script>
	export default {
		data() {
			const currentDate = this.getDate({
				format: true
			})
			const starDate = this.getDate('start')
			return {
				pageOpc:0,
				dataList:[],
				starTime: starDate,
				endTime: currentDate,
				date: currentDate,
				dateFlag:false,
				totalMoney:0
			}
		},
		onLoad() {
			this.getData()
		},
		onReady(){
			setTimeout(() => {
				this.pageOpc=1
			}, 100)
		},
		// 触底刷新
		// onReachBottom() {
		// 	if (this.more) {
		// 		this.getData()
		// 	}
		// },
		// 下拉刷新
		onPullDownRefresh: function() {
			this.freshList();
			this.$tools.loadIng()
			setTimeout(() => {
				uni.stopPullDownRefresh()
			}, 500)
		},
		methods: {
			copy(mobile){
				let that = this
				uni.setClipboardData({
					data:mobile,
					success: function() {
						console.log('success');
					}
				});
			},
			// 触底刷新
			lower() {
				if (this.more) {
					this.getData()
				}
			},
			// 获取时间
			getDate(type) {
				const date = new Date();
				date.setDate(date.getDate() - 1);
				if (type === 'start') {
					date.setDate(date.getDate() - 6);
				}
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();
				month = month > 9 ? month : '0' + month;
				day = day > 9 ? day : '0' + day;
				let result = `${year}-${month}`
				return result;
			},
			// 选择时间
			bindDateChange(e) {
				let index = e.currentTarget.dataset.index
				if (index == 0) {
					this.starTime = e.target.value
				} else {
					this.endTime = e.target.value
				}
			},
			// 重置
			reSet() {
				this.starTime = this.getDate('start')
				this.endTime = this.getDate({
					format: true
				})
			},
			// 提交
			submit() {
				this.freshList();
				this.closeDate();
			},
			showDate(){
				this.dateFlag=!this.dateFlag
			},
			closeDate(){
				this.dateFlag=false
			},
			changeNav(index){
				this.currmentIndex=index
				this.freshList();
			},
			// 刷新列表
			freshList() {
				this.page = 1
				this.more = true
				this.status = 'loading'
				this.dataList = []
				this.getData();
			},
			getData(){
				let self=this
				this.$request.post(this.$api.cashoutList, {
					store_id:uni.getStorageSync('store_id'),
					date:this.starTime
				}, {
					token:true
				}).then(res => {
					if (res.code == 1) {
						let {
							data = {}
						} = res;
						let newArray =data.list
						this.totalMoney=data.total_money
						self.dataList=newArray;
					}
				}).finally(() => {
					setTimeout(()=>{
						this.$tools.hideLoading()
					}, 1000)
				})
			},
		}
	}
</script>

<style lang="scss">
	.content{
		padding: 0 36upx;
	}
	.VerticalMain {
		flex: auto;
		padding-top: 10rpx;
	}
	.top-box{
		padding-bottom: 30upx;
		.triangle {
			border-top-color: #FFFFFF;
		}
		.screen-box{
			.date-box{
				font-size: 28upx;
				font-family: PingFang SC;
				font-weight: 500;
				line-height: 60upx;
				color: #FFFFFF;
				.calendar-icon{
					width: 48upx;
					height: 48upx;
					margin-right: 24upx;
				}
			}
		}
	}
	.total-box{
		font-size: 24upx;
		font-family: PingFang SC;
		font-weight: 400;
		line-height: 34upx;
		color: #5FD4FD;
		border-top: 2upx solid #36355E;
		border-bottom: 2upx solid #36355E;
		padding: 44upx 0 42upx 0;
		.total-num{
			font-size: 48upx;
			font-family: PingFang SC;
			font-weight: 500;
			line-height: 66upx;
			color: #5FD4FF;
		}
	}
	.data-box{
		margin-top: 40upx;
		.data-item{
			margin-top: 20upx;
			border-bottom: 1rpx solid #36355E;
			font-size: 36rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #5FD4FD;
			padding-bottom: 20upx;
			.left{
				font-size: 28rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #FFFFFF;
				line-height: 40upx;
				.jz{
					color: #5FD4FD;
				}
			}
		}
	}
	.date-boxs{
		padding: 30rpx;
		z-index: 999;
		border-bottom: 1rpx solid rgba(71, 73, 84, .5);
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		background-color: #040336;
		.date-title {
			font-size: 30rpx;
			font-family: PingFang;
			font-weight: 500;
			color: #FFFFFF;
			margin-bottom: 26rpx;
		}
	
		.date-cont {
			.screen-item {
				width: 80%;
				height: 66rpx;
				line-height: 66rpx;
				text-align: center;
				border: 1rpx solid #26BCFD;
				color: #323232;
				font-size: 28rpx;
				border-radius: 6rpx;
				padding: 0 30rpx;
				margin: auto;
				.select-input {
					font-size: 26rpx;
					font-family: PingFang;
					font-weight: 400;
					color: #26BCFD;
				}
	
				picker {
					width: 100%;
					text-align: left;
				}
	
				.triangle {
					border-top-color: #FFFFFF;
				}
			}
		}
		.determine-btn {
			margin-top: 40rpx;
			justify-content: center;
			view {
				width: 230rpx;
				height: 80rpx;
				line-height: 80rpx;
				text-align: center;
				font-size: 26rpx;
				font-family: PingFang;
				font-weight: 500;
				color: #26BCFD;
				border: 1rpx solid #26BCFD;
				border-radius: 20rpx;
				margin-right: 30upx;
			}
		
			.determine {
				background:#26BCFD;
				color: #FFFFFF;
				border: none;
			}
		}
	}
	.mask-wrap {
		position: fixed;
		top: 0;
		bottom: 0;
		left: 0;
		right: 0;
		margin: auto;
		z-index: 99;
		background: rgba(0, 0, 0, .4);
	}
	.empty-box{
		width: 476upx;
		height: 280upx;
		margin:250upx auto;
	}
	.tips-box{
		font-size: 28rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #8C98E3;
	}
</style>
